/*
    XTU OJ: 1191
    by: fifth_light
*/

#include <stdio.h>
#include <string.h>
#include <assert.h>

int main(void) {
    char num[5];
    while (1) {
        if (scanf(" %4[0-9]", num) <= 0) {
            break;
        }
        if (strcmp(num, "0") == 0) {
            break;
        }
        int cnt = 0;
        while (1) {
            if (strcmp(num, "6174") == 0) {
                break;
            }
            char A[5] = {0};
            char B[5] = {0};
            memcpy(A, num, 4);
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 3; j++) {
                    if (A[j] > A[j + 1]) {
                        char tmp = A[j];
                        A[j] = A[j + 1];
                        A[j + 1] = tmp;
                    }
                }
            }
            for (int i = 0; i < 4; i++) {
                B[3 - i] = A[i];
            }
            int a, b, n;
            if (sscanf(A, "%d", &a) <= 0) {
                assert(0);
            }
            if (sscanf(B, "%d", &b) <= 0) {
                assert(0);
            }
            n = b - a;
            snprintf(num, 5, "%04d", n);
            cnt++;
        }
        printf("%d\n", cnt);
    }
    return 0;
}
